<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="报价编号" prop="quotationNo">
        <el-input
          v-model="queryParams.quotationNo"
          placeholder="请输入报价编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="甲方单位" prop="clientUnit">
        <el-input
          v-model="queryParams.clientUnit"
          placeholder="请输入甲方单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="甲方联系电话" prop="clientContactPhone">
        <el-input
          v-model="queryParams.clientContactPhone"
          placeholder="请输入甲方联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价有效期">
        <el-date-picker
          v-model="daterangeQuotationValidity"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="付款方式" prop="paymentMethod">
        <el-select v-model="queryParams.paymentMethod" placeholder="请选择付款方式" clearable>
          <el-option
            v-for="dict in dict.type.qt_payment_method"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发票类型" prop="invoiceType">
        <el-select v-model="queryParams.invoiceType" placeholder="请选择发票类型" clearable>
          <el-option
            v-for="dict in dict.type.qt_invoice_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="税号" prop="taxNumber">
        <el-input
          v-model="queryParams.taxNumber"
          placeholder="请输入税号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价单位" prop="quotingUnit">
        <el-input
          v-model="queryParams.quotingUnit"
          placeholder="请输入报价单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="quotingContact">
        <el-input
          v-model="queryParams.quotingContact"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="quotingContactPhone">
        <el-input
          v-model="queryParams.quotingContactPhone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价日期">
        <el-date-picker
          v-model="daterangeQuotationDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="场所状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择场所状态" clearable>
          <el-option
            v-for="dict in dict.type.qt_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['quotation:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['quotation:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['quotation:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['quotation:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" prop="quotationId" />
      <el-table-column label="报价编号" align="center" prop="quotationNo" />
      <el-table-column label="甲方单位" align="center" prop="clientUnit" >
        <template slot-scope="scope">
          <p class="label">{{scope.row.clientUnit +" / "}} {{scope.row.clientContactPhone}}</p>
        </template>
      </el-table-column>
      <el-table-column label="报价有效期" align="center" prop="quotationValidity" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.quotationValidity, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总价" align="center" prop="price" />
      <el-table-column label="报价日期" align="center" prop="quotationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.quotationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.qt_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间/更新时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span><br>
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleInfo(scope.row)"
          >打印报价单</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['quotation:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['quotation:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改报价对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="报价编号" prop="quotationNo">
              <el-input v-model="form.quotationNo" placeholder="请输入报价编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报价有效期" prop="quotationValidity">
              <el-date-picker clearable
                              v-model="form.quotationValidity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择报价有效期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="甲方单位" prop="clientUnit">
              <el-input v-model="form.clientUnit" placeholder="请输入甲方单位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="甲方联系电话" prop="clientContactPhone">
              <el-input v-model="form.clientContactPhone" placeholder="请输入甲方联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="传真" prop="fax">
              <el-input v-model="form.fax" placeholder="请输入传真" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="收件人" prop="recipient">
              <el-input v-model="form.recipient" placeholder="请输入收件人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="付款方式" prop="paymentMethod">
              <el-select v-model="form.paymentMethod" placeholder="请选择付款方式" @change="handlePaymentMethodChange">
                <el-option
                  v-for="dict in dict.type.qt_payment_method"
                  :key="dict.value"
                  :label="dict.label+':'+dict.raw.remark"
                  :value="dict"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="付款方式说明" prop="paymentMethodDescription">
              <el-input v-model="form.paymentMethodDescription"  placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="货期（天）" prop="deliveryPeriod">
              <el-input-number v-model="form.deliveryPeriod" placeholder="请输入货期" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工期(天)" prop="constructionPeriod">
              <el-input v-model="form.constructionPeriod" placeholder="请输入施工期" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工/交货地点" prop="constructionDeliveryLocation">
              <el-input v-model="form.constructionDeliveryLocation"  placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发票类型" prop="invoiceType">
              <el-select v-model="form.invoiceType" placeholder="请选择发票类型">
                <el-option
                  v-for="dict in dict.type.qt_invoice_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">
            <el-form-item label="总价（元）" prop="price">
              <el-input-number v-model="form.price" placeholder="请输入总价" />
            </el-form-item>
          </el-col>-->
          <el-col :span="8">
            <el-form-item label="税率（%）" prop="taxRate">
              <el-input-number v-model="form.taxRate" :min="0.0000" placeholder="请输入税率" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="质量保修期（天）" prop="qualityWarrantyPeriod">
              <el-input v-model="form.qualityWarrantyPeriod" placeholder="请输入质量保修期" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="乙方指定收款账户单位名称" prop="payeeUnitName">
              <el-input v-model="form.payeeUnitName" placeholder="请输入乙方指定收款账户单位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开户行" prop="payeeBank">
              <el-input v-model="form.payeeBank" placeholder="请输入开户行" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="账号" prop="payeeAccountNumber">
              <el-input v-model="form.payeeAccountNumber" placeholder="请输入账号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="税号" prop="taxNumber">
              <el-input v-model="form.taxNumber" placeholder="请输入税号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报价单位" prop="quotingUnit">
              <el-input v-model="form.quotingUnit" placeholder="请输入报价单位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="quotingContact">
              <el-input v-model="form.quotingContact" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="电话" prop="quotingContactPhone">
              <el-input v-model="form.quotingContactPhone" placeholder="请输入电话" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报价日期" prop="quotationDate">
              <el-date-picker clearable
                              v-model="form.quotationDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择报价日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专用章" prop="specialSeal">
              <image-upload v-model="form.specialSeal"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.qt_status"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总价(人民币)" prop="isDelete">
              {{ getFormPrice() }} 元
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="" prop="isDelete">
              {{ numberToChinese(form.price)  }} 元
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="center">报价详情明细信息</el-divider>


        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddYtQuotationDetail">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteYtQuotationDetail">删除</el-button>
          </el-col>
        </el-row>
        <el-tabs v-model="activeName" type="card" @tab-click="">
          <el-tab-pane label="添加报价明细" name="first">
            <el-table :data="ytQuotationDetailList"  show-summary :summary-method="getSummaries" :row-class-name="rowYtQuotationDetailIndex" @selection-change="handleYtQuotationDetailSelectionChange" ref="ytQuotationDetail">
              <el-table-column type="selection" width="50" align="center" />
              <el-table-column label="序号" align="center" prop="index" width="50"/>
              <el-table-column label="名称" prop="name" >
                <template slot-scope="scope">
                  <el-input v-model="scope.row.name" placeholder="请输入名称" />
                </template>
              </el-table-column>
              <el-table-column label="规格型号" prop="specificationModel" >
                <template slot-scope="scope">
                  <el-input v-model="scope.row.specificationModel" placeholder="请输入规格型号" />
                </template>
              </el-table-column>
              <el-table-column label="梯号" prop="elevatorNumber" >
                <template slot-scope="scope">
                  <el-input v-model="scope.row.elevatorNumber" placeholder="请输入梯号" />
                </template>
              </el-table-column>
              <el-table-column label="单位" prop="unit" >
                <template slot-scope="scope">
                  <el-input v-model="scope.row.unit" placeholder="请输入单位" />
                </template>
              </el-table-column>
              <el-table-column label="数量" prop="quantity" >
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.quantity" :min="1" placeholder="请输入数量" @change="getTotalPrice(scope)"/>
                </template>
              </el-table-column>
              <el-table-column label="单价（元）" prop="unitPrice" >
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.unitPrice" placeholder="请输入单价" @change="getTotalPrice(scope)" />
                </template>
              </el-table-column>
              <el-table-column label="合计（元）" prop="totalPrice" >
                <template slot-scope="scope">
                  <p class="left-arrow">{{scope.row.totalPrice}} 元</p>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="从报价项模板选择报价明细" name="second">
            <el-form :model="queryParamsDemo" ref="queryForm" size="small" :inline="true"  label-width="110px">
              <el-form-item label="类型" prop="type">
                <el-select v-model="queryParamsDemo.type" placeholder="请选择类型" clearable>
                  <el-option
                    v-for="dict in dict.type.qt_demo_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="名称" prop="name">
                <el-input
                  v-model="queryParamsDemo.name"
                  placeholder="请输入名称"
                  clearable
                  @keyup.enter.native="handleQuery"
                />
              </el-form-item>

              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryDemo">搜索</el-button>
              </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button
                  type="primary"
                  plain
                  icon="el-icon-plus"
                  size="mini"
                  @click="handleAddDemo"
                >勾选新增</el-button>
              </el-col>
            </el-row>
            <el-table v-loading="loadingDemo" :data="demoList" @selection-change="handleSelectionChangeDemo">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" type="index" align="center" prop="id" />
              <el-table-column label="类型" align="center" prop="type">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.qt_demo_type" :value="scope.row.type"/>
                </template>
              </el-table-column>
              <el-table-column label="名称" align="center" prop="name" />
              <el-table-column label="规格型号" align="center" prop="specificationModel" />
              <el-table-column label="备注" align="center" prop="remark" />
              <el-table-column label="数量" align="center" prop="quantity" >
                <template slot-scope="scope">
                  <span>{{ scope.row.quantity }}{{scope.row.unit}}</span>
                </template>
              </el-table-column>
              <el-table-column label="单价（元）" align="center" prop="unitPrice" />
              <el-table-column label="合计（元）" align="center" prop="totalPrice" />
            </el-table>

            <pagination
              v-show="totalDemo>0"
              :total="totalDemo"
              :page.sync="queryParamsDemo.pageNum"
              :limit.sync="queryParamsDemo.pageSize"
              @pagination="getList"
            />
          </el-tab-pane>
        </el-tabs>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/quotation/info";
import { listDemo } from "@/api/quotation/demo";

export default {
  name: "Info",
  dicts: ['qt_status', 'qt_invoice_type', 'qt_payment_method', 'sys_yes_no', 'qt_demo_type'],
  data() {
    return {
      activeName: 'first',
      // 遮罩层
      loading: true,
      loadingDemo: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedYtQuotationDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      totalDemo: 0,
      // 报价表格数据
      infoList: [],
      demoList: [],
      newDemoList: [],
      // 报价详情明细表格数据
      ytQuotationDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openInfo: false,
      // 删除标志时间范围
      daterangeQuotationValidity: [],
      // 删除标志时间范围
      daterangeQuotationDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        quotationNo: null,
        clientUnit: null,
        clientContactPhone: null,
        quotationValidity: null,
        fax: null,
        recipient: null,
        paymentMethod: null,
        paymentMethodDescription: null,
        deliveryPeriod: null,
        constructionPeriod: null,
        constructionDeliveryLocation: null,
        invoiceType: null,
        price: null,
        taxRate: null,
        qualityWarrantyPeriod: null,
        payeeUnitName: null,
        payeeBank: null,
        payeeAccountNumber: null,
        taxNumber: null,
        quotingUnit: null,
        quotingContact: null,
        quotingContactPhone: null,
        quotationDate: null,
        specialSeal: null,
        clientConfirmationSeal: null,
        isAgreeQuotation: null,
        otherOpinions: null,
        status: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
      },
      // 查询参数
      queryParamsDemo: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        name: null,
        specificationModel: null,
        unit: null,
        quantity: null,
        unitPrice: null,
        totalPrice: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        quotationNo: [
          { required: true, message: "报价编号不能为空", trigger: "blur" }
        ],
        clientUnit: [
          { required: true, message: "甲方单位不能为空", trigger: "blur" }
        ],
        clientContactPhone: [
          { required: true, message: "甲方联系电话不能为空", trigger: "blur" }
        ],
        quotationValidity: [
          { required: true, message: "报价有效期不能为空", trigger: "blur" }
        ],
        quotingUnit: [
          { required: true, message: "报价单位不能为空", trigger: "blur" }
        ],
        quotationDate: [
          { required: true, message: "报价日期不能为空", trigger: "blur" }
        ],
        createdBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDemoList();
  },
  methods: {
    /** 查询报价列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeQuotationValidity && '' != this.daterangeQuotationValidity) {
        this.queryParams.params["beginQuotationValidity"] = this.daterangeQuotationValidity[0];
        this.queryParams.params["endQuotationValidity"] = this.daterangeQuotationValidity[1];
      }
      if (null != this.daterangeQuotationDate && '' != this.daterangeQuotationDate) {
        this.queryParams.params["beginQuotationDate"] = this.daterangeQuotationDate[0];
        this.queryParams.params["endQuotationDate"] = this.daterangeQuotationDate[1];
      }
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 查询报价项目模板
    getDemoList() {
      this.loadingDemo = true;
      listDemo(this.queryParamsDemo).then(response => {
        this.demoList = response.rows;
        this.totalDemo = response.total;
        this.loadingDemo = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        quotationId: null,
        quotationNo: null,
        clientUnit: null,
        clientContactPhone: null,
        quotationValidity: null,
        fax: null,
        recipient: null,
        paymentMethod: null,
        paymentMethodDescription: null,
        deliveryPeriod: null,
        constructionPeriod: null,
        constructionDeliveryLocation: null,
        invoiceType: null,
        price: null,
        taxRate: null,
        qualityWarrantyPeriod: null,
        payeeUnitName: null,
        payeeBank: null,
        payeeAccountNumber: null,
        taxNumber: null,
        quotingUnit: null,
        quotingContact: null,
        quotingContactPhone: null,
        quotationDate: null,
        specialSeal: null,
        clientConfirmationSeal: null,
        isAgreeQuotation: null,
        otherOpinions: null,
        status: '草稿',
        remark: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        delFlag: null
      };
      this.ytQuotationDetailList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQueryDemo() {
      this.queryParamsDemo.pageNum = 1;
      this.getDemoList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeQuotationValidity = [];
      this.daterangeQuotationDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.quotationId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 多选框选中项目模板数据
    handleSelectionChangeDemo(selection) {
      this.newDemoList = selection;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.quotationNo = 'YTB'+this.parseTime(Date.now(), '{y}{m}{d}{h}{i}{s}');
      this.open = true;
      this.title = "添加报价";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const quotationId = row.quotationId || this.ids
      getInfo(quotationId).then(response => {
        this.form = response.data;
        this.ytQuotationDetailList = response.data.ytQuotationDetailList;
        this.open = true;
        this.title = "修改报价";
      });
    },
    /** 打印按钮操作 */
    handleInfo(row) {
      const quotationId = row.quotationId ;
      this.$router.push("/quotation/quotation-info/info/" + quotationId);

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.ytQuotationDetailList = this.ytQuotationDetailList;
          if (this.form.quotationId != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const quotationIds = row.quotationId || this.ids;
      this.$modal.confirm('是否确认删除报价编号为"' + quotationIds + '"的数据项？').then(function() {
        return delInfo(quotationIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 报价详情明细序号 */
    rowYtQuotationDetailIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 报价详情明细添加按钮操作 */
    handleAddYtQuotationDetail() {
      let obj = {};
      obj.name = "";
      obj.specificationModel = "";
      obj.elevatorNumber = "";
      obj.remark = "";
      obj.unit = "";
      obj.quantity = "";
      obj.unitPrice = "";
      obj.totalPrice = "";
      obj.createdBy = "";
      obj.createdTime = "";
      obj.updatedBy = "";
      obj.updatedTime = "";
      this.ytQuotationDetailList.push(obj);
    },
    /** 报价详情明细删除按钮操作 */
    handleDeleteYtQuotationDetail() {
      if (this.checkedYtQuotationDetail.length == 0) {
        this.$modal.msgError("请先选择要删除的报价详情明细数据");
      } else {
        const ytQuotationDetailList = this.ytQuotationDetailList;
        const checkedYtQuotationDetail = this.checkedYtQuotationDetail;
        this.ytQuotationDetailList = ytQuotationDetailList.filter(function(item) {
          return checkedYtQuotationDetail.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleYtQuotationDetailSelectionChange(selection) {
      this.checkedYtQuotationDetail = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('quotation/info/export', {
        ...this.queryParams
      }, `报价单信息_${new Date().getTime()}.xlsx`)
    },
    /** 支付方式赋值*/
    handlePaymentMethodChange(dict) {
      this.form.paymentMethod = dict.value
      this.form.paymentMethodDescription = dict.raw.remark
    },
    /** 新增报价详细*/
    handleAddDemo(){
      if (this.newDemoList.length == 0) {
        this.$modal.msgError("请先选择要添加的报价项模板数据");
      } else {
        const ytQuotationDetailList = this.newDemoList;
        this.ytQuotationDetailList = ytQuotationDetailList.map((item) => {
          return item;
        });
        this.activeName = 'first';
      }
    },
    /** 计算每一行总价*/
    getTotalPrice(scope){
      this.ytQuotationDetailList[scope.$index].totalPrice = scope.row.quantity * scope.row.unitPrice;
    },

    /** 计算ytQuotationDetailList 字段totalPrice之和*/
    getFormPrice() {
      this.form.price = this.ytQuotationDetailList.reduce((total, item) => {
        return total + item.totalPrice;
      }, 0);

      return this.form.price;
    },

    /** 表格自动计算合计*/
    getSummaries(param){

      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总价';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value)) && index === 8) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += ' 元';
        } else {
          sums[index] = '';
        }
      });

      return sums;
    }

  }
};
</script>
